<?php
App::import('Controller', 'FutureDms');
App::import('Model', 'FutureDm');
App::import('Model', 'User');
App::import('Component', 'Session');
App::import('Component', 'Auth');

class FutureDmsControllerTest extends ControllerTestCase{
    
   /** These two lines are of no use as, first of all, no such
     * Fixutres exist and, second, the $autoFixtures variable 
     * Which controls loading of the fixtures is set to false, 
     * with no other function calling CakeTestCase::loadFixtures()
     */
    public $fixtures = array('app.future_dm', 'app.comment');
    public $autoFixtures = false;
    
    var $components = array('Auth', 'Cookie', 'Session', 'RequestHandler');

    public function startTest(){
        
        $this->FutureDms = new FutureDmsControllertest();
        $this->FutureDms->constructClasses();
	    $this->FutureDm = new FutureDm();
        
        $this->FutureDms->initialize($this->FutureDms);
        $this->FutureDmsController = $this->generate('FutureDms', array(
           'components' => array('Session', 'Auth' => array('User'), 'RequestHandler') //We mock the Auth Component here
               ));
        $this->FutureDm = ClassRegistry::init('FutureDm');
        $result = $this->FutureDm->find('all', array('conditions' => array('id' => 778), 'fields' => 'approved'));
        if($result){

        } else {
            $this->FutureDm->save(array('id' => '778', 'userID' => 9, 'messageText' => 'test 778'));
        }
    }
    /*
     * @access: public
     * 
     * @Description: This function tests the deleteJEDm function in the FutureDmsController.
     * @author Mark Milad
     */
     public function testdeleteDM() 
        {


        $this->testAction('/futuredms/deleteJEDm/777');
        $result = $this->FutureDm->find('all', array('conditions' => array('id' => 777)));
        $this->assertEquals(array(), $result);
       }

    /**
     * Tests the function approve in the FutureDmsController
     * @author Kareem Yousry
     */
    public function testApproveDM() {

        $this->FutureDmsController->Auth->staticExpects($this->any())
        ->method('User', 'User')
        ->with($this->logicalOr(
            $this->equalTo('userID'), $this->equalTo('accID'), $this->equalTo('admin')))
        ->will($this->returnCallback(array($this, 'approveCallBack')));

        //disproving Dms incase they were formerly approved.
        $this->FutureDm->updateAll(array('FutureDm.approved' => 'false'),
            array('FutureDm.id' => '778'));

        //Testing the action.
        $this->testAction('/futuredms/approve/778');
        $result = $this->FutureDm->find('all', array('conditions' => array('id' => 778), 'fields' => 'approved'));
        $this->assertEquals('1',$result['0']['FutureDm']['approved']);
    }
    /**
     * Tests the function delete in the FutureTweetsController
     * @author Kareem Yousry
     */
    public function testDelete() {

        $this->FutureDmsController->Auth->staticExpects($this->any())
        ->method('User', 'User')
        ->with($this->logicalOr(
            $this->equalTo('userID'), $this->equalTo('accID'), $this->equalTo('admin')))
        ->will($this->returnCallback(array($this, 'approveCallBack')));

        $this->testAction('futuredms/delete/778');
        $result = $this->FutureDm->find('all', array('conditions' => array('id' => 778)));
        $this->assertEquals(array(), $result);
    }

    public function approveCallBack($foo) {

        if ($foo == 'accID'){
            return 1;

        } else {

            if ($foo == 'userID') {
                return 1;
            }
        }
        return 0;
    }


}

?>